using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;

namespace Telerik.GridExamplesCSharp.DataEditing.AllEditableColumns
{
    public partial class thongtinkhac_giapphepmt : System.Web.UI.Page
    {
        public int i = 1;
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        /* protected void RadGrid_XLsp_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
         {
             GridEditableItem item = (GridEditableItem)e.Item;
             String id = item.GetDataKeyValue("masp").ToString();

             if (e.Exception != null)
             {
                 e.KeepInEditMode = true;
                 e.ExceptionHandled = true;
                 SetMessage("Product with ID " + id + " cannot be updated. Reason: " + e.Exception.Message);
             }
             else
             {
                 SetMessage("Product with ID " + id + " is updated!");
             }
         }*/
        protected void RadGrid_XLsp_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.KeepInEditMode = true;
                e.ExceptionHandled = true;
                DisplayMessage(true, "Sanpham " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["SoGP"] + " cannot be updated. Reason: " + e.Exception.Message);
            }
            else
            {
                DisplayMessage(false, "sanpham " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["SoGP"] + " updated");
            }
        }

        protected void RadGrid_XLsp_ItemInserted(object source, GridInsertedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                e.KeepInInsertMode = true;
                DisplayMessage(true, "Employee cannot be inserted. Reason: " + e.Exception.Message);
            }

            else
            {
                DisplayMessage(false, "Employee inserted");
            }
        }

        protected void RadGrid_Xlsp_ItemDeleted(object source, GridDeletedEventArgs e)
        {
            GridDataItem dataItem = (GridDataItem)e.Item;
            String id = dataItem.GetDataKeyValue("SoGP").ToString();


            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                SetMessage("Product with ID " + id + " cannot be deleted. Reason: " + e.Exception.Message);
            }
            else
            {
                SetMessage("Product with ID " + id + " is deleted!");
            }
        }

        private void DisplayMessage(string text)
        {
            RadGrid_XLsp.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));
        }

        private void SetMessage(string message)
        {
            gridMessage = message;
        }

        private string gridMessage = null;
        protected void RadGrid_XLsp_DataBound(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(gridMessage))
            {
                DisplayMessage(gridMessage);
            }
        }
        private void DisplayMessage(bool isError, string text)
        {
            Label label = (isError) ? this.Label1 : this.Label2;
            label.Text = text;
        }

        protected void RadGrid_XLsp_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
            {
                GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid_XLsp.MasterTableView.GetColumn("EditCommandColumn");
                editColumn.Visible = false;
            }
            else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
            {
                e.Canceled = true;
            }
            else
            {
                GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid_XLsp.MasterTableView.GetColumn("EditCommandColumn");
                if (!editColumn.Visible)
                    editColumn.Visible = true;
            }
        }
        /* protected void RadGrid_XLsp_PreRender(object sender, EventArgs e)
         {
             if (!Page.IsPostBack)
             {
                 RadGrid_XLsp.EditIndexes.Add(0);
                 RadGrid_XLsp.Rebind();
             }
         }*/

    }
}